package com.yanqu.road.server.channelserver.cmd.activity.entername;

import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.cross3.activity.EnterNameProto;
import com.yanqu.road.server.channelserver.cmd.ChannelCommand;
import com.yanqu.road.server.channelserver.logic.ChannelMessageHelper;
import com.yanqu.road.server.channelserver.manager.activity.entername.ChannelEnterNameMgr;
import com.yanqu.road.server.channelserver.manager.activity.entername.EnterNameModel;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.protocol.ChannelProtocol;
import com.yanqu.road.server.protocol.Protocol;

@Cmd(code = ChannelProtocol.N_ENTER_NAME_ZONE_COUNT, desc = "获取报名统计")
public class ChannelEnterNameCountCmd extends ChannelCommand {

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        return true;
    }

    @Override
    public void execute(YanQuMessage packet) throws Exception {

        EnterNameProto.ChannelEnterNameCountReqMsg reqMsg = EnterNameProto.ChannelEnterNameCountReqMsg.parseFrom(packet.getBytes());
        int activityId = reqMsg.getActivityId();
        EnterNameProto.EnterNameCountRespMsg.Builder clientMsg = EnterNameProto.EnterNameCountRespMsg.newBuilder();
        clientMsg.setRet(0);
        EnterNameModel model = ChannelEnterNameMgr.getEnterNameModelMap().get(activityId);
        if(model != null){
            clientMsg.setList(model.getCountListMsg());
        }else {
            clientMsg.setRet(-1);
        }
        ChannelMessageHelper.sendGamePacket(Protocol.U_ENTER_NAME_ZONE_COUNT, clientMsg, reqMsg.getUserKey().getChannelId(),
                reqMsg.getUserKey().getServerId(), reqMsg.getUserKey().getUserId());
    }

    @Override
    public void sendData() {

    }
}
